<script type="text/html" template lay-done="layui.data.fileListDone(d)">
    <div class="layui-fluid">
        <table id="fileTable" lay-filter="custom-fileTable-filter"></table>
    </div>
</script>

<!-- 文件模板 -->
<script type="text/html" id="oplTpl">
    <button type="button" class="layui-btn layui-btn-downFile" lay-event="downFile">下载附件</button>
</script>

<script>
    layui.data.fileListDone = function (d) {
        layui.use(['admin', 'table'], function(){
            var admin = layui.admin,
                table = layui.table,
                tools = layui.tools,
            taskId = d.params.taskid;

            initFileTable(taskId);

            //加载文件列表
            function initFileTable(taskId) {
                admin.req({
                    url: 'myapi/DC/api/rest/web/custom/IndexTaskDeptFileQery',
                    data: {
                        taskid: taskId
                    },
                    done: function(res){
                        var result = res.data;
                        if(result.retcode == 0) {
                            table.render({
                                elem: '#fileTable',
                                height: 350,
                                even: true,
                                skin: 'nob',
                                text: {
                                    none: '<div class="no-data-tips"><img src="/dist/style/res/about/empty.png"><p style="color:#DBDBDB;">暂无数据</p></div>'
                                },
                                data: result.data,
                                cols: [[
                                    { field: 'dept_name', title: '单位名称', align: 'center' },
                                    { field: 'filename', title: '附件名称', align: 'center' },
                                    { field: 'url', title: '操作', toolbar: '#oplTpl', align: 'center'}
                                ]]
                            })
                        }
                    }
                })
            }

            //监听工具栏
            table.on('tool(custom-fileTable-filter)', function(obj){
                var event = obj.event,
                    data = obj.data;
                switch (event) {
                    case 'downFile':
                        var url = 'myapi/DC'+ data.url,
                            name = data.filename;
                        tools.downMethodfunction(url, name);
                        break;
                    default:
                        break;
                }
            })
        })
    }
</script>